package com.gxgeek.springbootsendmessage;

import com.gxgeek.springbootsendmessage.dto.MailDTO;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;
import java.io.IOException;

/**
 * @author gaoxing
 * @create 2017-12-08 下午3:13
 */
@RestController
@Slf4j
public class SendController {

    @Autowired
    SendService sendService;
    @GetMapping("/sendMail")
    public void sendMail(MailDTO mailDTO){
        log.info(String.valueOf(mailDTO));
        sendService.sendSimple(mailDTO.getTo(),mailDTO.getTitle(),mailDTO.getContent());
    }
    @GetMapping("/sendAttachmentsMail")
    public void sendAttachmentsMail(MailDTO mailDTO) throws MessagingException {
        log.info(String.valueOf(mailDTO));
        sendService.sendAttachmentsMail(mailDTO.getTo(),mailDTO.getTitle(),mailDTO.getContent());
    }
    @GetMapping("/sendInlineMail")
    public void sendInlineMail(MailDTO mailDTO) throws MessagingException {
        log.info(String.valueOf(mailDTO));
        sendService.sendInlineMail(mailDTO.getTo(),mailDTO.getTitle(),mailDTO.getContent());
    }
    @GetMapping("/sendTemplateMail")
    public void sendTemplateMail(MailDTO mailDTO) throws MessagingException, IOException, TemplateException {
        log.info(String.valueOf(mailDTO));
        sendService.sendTemplateMail(mailDTO.getTo(),mailDTO.getTitle(),mailDTO.getContent());
    }
}
